package com.tangcan.blog.Mapper;

import com.tangcan.blog.Entity.BlogContent;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface BlogContentMapper {

    @Select("SELECT * FROM BlogContent ORDER BY Id DESC")
    List<BlogContent>GetAll();

    @Select("SELECT * FROM BlogContent ORDER BY Id DESC LIMIT #{num1} ,#{num2}")
    List<BlogContent> GetPage(int num1, int num2);

    @Select("SELECT * FROM BlogContent WHERE Tag = #{Tag} ORDER BY Id DESC LIMIT #{num1} ,#{num2}")
    List<BlogContent> GetPageByTag(String Tag,int num1, int num2);

    @Select("SELECT * FROM BlogContent WHERE Id = #{Id}")
    BlogContent GetBlog (int Id);

    @Select("SELECT COUNT(Id) FROM BlogContent")
    int GetCount();

    @Select("SELECT COUNT(Id) FROM BlogContent WHERE Tag = #{Tag}")
    int GetCountByTag(String Tag);


    @Insert("INSERT INTO BlogContent (Title,Content,Tag,BigImgSrc,CreateTime,UpdateTime,UserId) VALUES ( #{Title},#{Content},#{Tag},#{BigImgSrc},#{CreateTime},#{UpdateTime},#{UserId})")
    int InserBlog(BlogContent blogContent);

    @Update("UPDATE BlogContent SET Title = #{Title},Content = #{Content} , Tag=#{Tag},BigImgSrc=#{BigImgSrc},UpdateTime=#{UpdateTime} WHERE Id = #{Id}")
    int UpdateBlogById(BlogContent blogContent);

    @Delete("DELETE FROM BlogContent WHERE Id = #{Id}")
    int RemoveBlog(int Id);

    @Select("SELECT DISTINCT Tag  FROM BlogContent")
    List<String> GetAllTag();

//    模糊查询
    @Select("SELECT * FROM BlogContent WHERE Title LIKE concat('%',#{keyWord},'%') OR  Content LIKE concat('%',#{keyWord},'%')" )
    List<BlogContent>SearchBlog(String keyWord);




}
